package com.lkm.app_ui.m.Imple.steelyard_auto;

import com.lkm.app_ui.m.Imple.steelyard_ser.SteelyardServerModuleSerialport;
import com.lkm.frame.entity.ResponEntityAbs;
import com.lkm.frame.task2.BackCallAdapter;
import com.lkm.frame.task2.Task;
import com.lkm.market2_0.m.steelyardserver.GoodsButtonInfoTo;
import com.lkm.market2_0.m.steelyardserver.SteelyardServerModule;
import com.lkm.market2_0.m.steelyardstatus.SteelyardStatusManagerModule;
import com.lkm.market2_0.m_imple.steelyardserver.server.AbsSendWriteTask;

import java.util.List;



public class SteelyardServerModuleAuto implements SteelyardServerModule {


    private SteelyardStatusManagerModule steelyardStatusManagerModule;
    private SteelyardServerModule proxy;



    public SteelyardServerModuleAuto(SteelyardStatusManagerModule steelyardStatusManagerModule, DeviceinitPo deviceinitPo) {
        this.steelyardStatusManagerModule = steelyardStatusManagerModule;
        upProxy(deviceinitPo);

        HoldLoadDeviceinitPoTask holdLoadDeviceinitPoTask = new HoldLoadDeviceinitPoTask(true);
        holdLoadDeviceinitPoTask.action();
        holdLoadDeviceinitPoTask.addBackCall(new BackCallAdapter<String, ResponEntityAbs<DeviceinitPo>>(){
            @Override
            public void onFinish(Task<?, String, ResponEntityAbs<DeviceinitPo>> task, ResponEntityAbs<DeviceinitPo> re) {
                super.onFinish(task, re);
                if(re.isSuccess()){
                    upProxy(re.getData());
                }
            }
        });
        holdLoadDeviceinitPoTask.execTask();
    }

    public void upProxy(DeviceinitPo deviceinitPo) {



        if (deviceinitPo == null) {
            deviceinitPo = new DeviceinitPo();
            deviceinitPo.comType = "1";
        }







//        if ("1".equals(deviceinitPo.comType))

        {
            if (proxy instanceof SteelyardServerModuleSerialport) {
                return;
            }
            proxy = new SteelyardServerModuleSerialport(steelyardStatusManagerModule);
        }


    }

    @Override
    public AbsSendWriteTask print(String steelyardMac, String table, String qr) {
        return proxy.print(steelyardMac, table, qr);
    }

    @Override
    public AbsSendWriteTask setGoodsButton(String steelyardMac, List<GoodsButtonInfoTo> goodsInfoTos) {
        return proxy.setGoodsButton(steelyardMac, goodsInfoTos);
    }

    @Override
    public AbsSendWriteTask setTitle(String steelyardMac, String title, String subTitle) {
        return proxy.setTitle(steelyardMac, title, subTitle);
    }

    @Override
    public AbsSendWriteTask setSteelyardRepairing(String steelyardMac) {
        return proxy.setSteelyardRepairing(steelyardMac);
    }

    @Override
    public AbsSendWriteTask setSteelyardOK(String steelyardMac) {
        return proxy.setSteelyardOK(steelyardMac);
    }

    @Override
    public AbsSendWriteTask setLockKeySwitch(String steelyardMac, boolean isLock) {
        return proxy.setLockKeySwitch(steelyardMac, isLock);
    }


    @Override
    public AbsSendWriteTask tickOK_block(String steelyardMac) {
        return proxy.tickOK_block(steelyardMac);
    }

    @Override
    public void stopServer() {
        proxy.stopServer();
    }
}
